package com.sywb.chuangyebao.contract;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;

import org.bining.footstone.rxjava.rxbus.RxBus;
import org.bining.footstone.utils.SharedUtils;

public interface BindingAlipayContract  {
    /**
     * 开始界面要实现的View
     */
    interface View extends BaseTokenContract.View {
        EditText getCode();
        EditText getAlipayAccount();
        EditText getAlipayName();
        Button getBtnConfirm();
    }

    /**
     * 开始界面要绑定的Presenter
     */
    class Presenter extends BaseTokenContract.Presenter<View> {
        private String code="";
        private String alipayAccount="";
        private String alipayName="";
        private Button btnConfirm;
        @Override
        public void onStart() {
            super.onStart();
            btnConfirm = mView.getBtnConfirm();
            btnConfirm.setOnClickListener(new android.view.View.OnClickListener() {
                @Override
                public void onClick(android.view.View v) {
                    code = mView.getCode().getText().toString().trim();
                    alipayAccount = mView.getAlipayAccount().getText().toString().trim();
                    alipayName = mView.getAlipayName().getText().toString().trim();
                    bindingAlipay();
                }
            });
        }

        private void bindingAlipay(){
            HttpUtils.bindingAlipay(code,alipayAccount,alipayName, new HttpCallback<String>() {
                @Override
                public void onStart() {
                    super.onStart();
                    onStartAsync();
                }

                @Override
                public void onSuccess(String s) {
                    RxBus.get().post(Constants.POST_BINDING_ALIPAY,s);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    showMessage(strMsg);
                }
            });
        }
    }
}
